/* -*- c++ -*- */
/*
 *   Copyright 2011,2012 Erik Persson
 *
 *   This file is part of the cell-sync-usrp project.
 *
 *   cell-sync-usrp is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   cell-sync-usrp is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with cell-sync-usrp.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef INCLUDED_WCDMA_RESAMPLER_CC_H
#define INCLUDED_WCDMA_RESAMPLER_CC_H

#include <gr_block.h>

class wcdma_resampler_cc;

/*
 * We use boost::shared_ptr's instead of raw pointers for all access
 * to gr_blocks (and many other data structures).  The shared_ptr gets
 * us transparent reference counting, which greatly simplifies storage
 * management issues.  This is especially helpful in our hybrid
 * C++ / Python system.
 *
 * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
 *
 * As a convention, the _sptr suffix indicates a boost::shared_ptr
 */
typedef boost::shared_ptr<wcdma_resampler_cc> wcdma_resampler_cc_sptr;

/*!
 * \brief Return a shared_ptr to a new instance of wcdma_resampler_cc.
 *
 * To avoid accidental use of raw pointers, wcdma_resampler_cc's
 * constructor is private.  wcdma_make_resampler_cc is the public
 * interface for creating new instances.
 */
wcdma_resampler_cc_sptr wcdma_make_resampler_cc (float scale);

/*!
 * \brief square a stream of floats.
 * \ingroup block
 *
 * \sa wcdma_square2_ff for a version that subclasses gr_sync_block.
 */
class wcdma_resampler_cc : public gr_block
{
private:
  // The friend declaration allows wcdma_make_resampler_cc to
  // access the private constructor.

  friend wcdma_resampler_cc_sptr wcdma_make_resampler_cc (float scale);

  wcdma_resampler_cc (float scale);  	// private constructor

  float d_scale;						// how the input should be scaled
  int d_position;						// the stepping position
  float d_scale_position;				// the scale stepping position
  gr_complex d_last;					// the last received buffered sample
  bool d_in_startup_state;				// indicates if this block is in its startup state

  gr_complex sample(gr_complex s1, gr_complex s2, float a);		// creates a new sample with interpolation between s1,s2. a is the weight.

 public:
  ~wcdma_resampler_cc ();	// public destructor

  // Where all the action really happens

  int general_work (int noutput_items,
		    gr_vector_int &ninput_items,
		    gr_vector_const_void_star &input_items,
		    gr_vector_void_star &output_items);
};

#endif /* INCLUDED_WCDMA_RESAMPLER_FF_H */
